import { useState, useEffect } from "react";
function useRequest(url, initValue) {
    const [data, setData] = useState(initValue)
    const [loading, setLoading] = useState(false);
    useEffect(() => {
        // 页面加载完毕之后立刻将loading设置为true 开始请求接口
        setLoading(true)
        setTimeout(() => {
            fetch(url)
                .then(res => res.json())
                .then(res => {
                    // 请求成功之后将loading设置为false
                    setLoading(false)
                    setData(res)
                })
        }, 1500);
    }, [url])
    return { loading, data }
}

export default useRequest;